﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using PlugNT.Cms.Model;
using PlugNT.Cms.BLL;
using PlugNT.Cms.Page;

namespace PlugNT.Cms.Web.Admin.Pre_Enterprise
{
    public partial class Admin : AdminPage
    {
        private Enterprise curEnterprise = new Enterprise();
        private string classno = "";
        private int pageSize = 15;

        protected void Page_Load(object sender, EventArgs e)
        {
            //权限检测
            this.CheckPower();

            classno = Request.QueryString["clsno"] == null ? "" : Request.QueryString["clsno"].Trim();
            if (!IsPostBack)
            {
                try
                {
                    Repeater_admin_bind();
                }
                catch (Exception ex) { Response.Redirect("../Message.aspx?message=绑定异常！" + ex.Message + "&z=no"); }
            }
        }


        #region 数据绑定
        void Repeater_admin_bind()
        {
            string gopage = (Request.QueryString["page"] == null) ? "0" : Request.QueryString["page"].Trim();
            int page = Convert.ToInt32(gopage);

            int recordCount = 0;
            DataTable dt = curEnterprise.GetList(pageSize, (page - 1), false, false, false, out recordCount);
            litPager.Text = PlugNT.Common.Pager.Pagination(recordCount, pageSize, page, "Admin.aspx", GetBindUrl(), "", true, true);

            Repeater_admin.DataSource = dt;
            Repeater_admin.DataBind();
        }
        #endregion

        #region 显示数据处理
        protected void Repeater_admin_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                Label Label_clsname = (Label)e.Item.FindControl("Label_clsname");
                DataRowView drv = (DataRowView)e.Item.DataItem;

            }
        }
        #endregion

        private string GetBindUrl()
        {
            return "clsno=" + classno + "&page";
        }

        //批量删除
        protected void ImageButton_all_del_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        {

            int nub = 0;
            for (int i = 0; i < Repeater_admin.Items.Count; i++)
            {
                int id = Convert.ToInt32(((HiddenField)Repeater_admin.Items[i].FindControl("hidid")).Value.Trim());
                CheckBox CK = (CheckBox)Repeater_admin.Items[i].FindControl("ID_list");
                if (CK.Checked)
                {
                    if (curEnterprise.Delete(id))
                    {
                        nub += 1;
                    }
                }
            }
            Response.Redirect("../Message.aspx?message=批量删除<b>" + nub + "</b>条信息成功！&z=yes");

        }
    }
}
